<?php
$name=$_GET['name'];
include'connect.php';

$q=$db->prepare("insert into sg_sites (name) values(:name)");
try{
    $q->execute(array(":name"=>$name));
}
catch (PDOException$e){
    switch($e->getCode()){
    case 1062: echo'alert("That name is already used for another site hosted on sitegeist");'; break;
    default: echo'alert("error: ',$e->getMessage(),'");';
    }
}


try{
//"CREATE TABLE `sitegeist`.`tess` (`index` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `tag` VARCHAR(56) NOT NULL, `plugin` VARCHAR(56) NOT NULL, `page` VARCHAR(56) NOT NULL, `value` BLOB NOT NULL, UNIQUE (`plugin`)) CHARACTER SET utf8 COLLATE utf8_bin;";
    $db->exec("create table `$name` (`index` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `tag` VARCHAR(56) NOT NULL, `plugin` VARCHAR(56) NOT NULL, `page` VARCHAR(56) NOT NULL, `value` BLOB NOT NULL, UNIQUE (`plugin`)) CHARACTER SET utf8 COLLATE utf8_bin;");
    $q=$db->prepare("insert into $name (tag,plugin,page,value) values(:tag,:plugin,:page,:value)");
    $q->execute(array(
        ":tag"=>"sitegeist",
        ":plugin"=>"base",
        ":page"=>"name",
        ":value"=>$name
    ));
}
catch (PDOException$e){
    switch($e->getCode()){
    default: echo'alert("error: ',$e->getMessage(),'");';
    }

}




//cleanup
unset($q);
$db=null;
?>
location.reload();